﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using DllDeezerDev;

namespace DllDezzerDev
{
   public class worldWeatherOnlineApi
    {

        public static string getMeteoVille(DateTime date,string ville)
        {
            string url_apiMeteo = "http://api.worldweatheronline.com/free/v1/weather.ashx?q=#ville#&format=xml&num_of_days=1&date=#jour#%2F#mois#%2F#annee#&key=7y24zksg9yrxcprghr35mn7x";

            
            string url_apiMeteoTrueDay = url_apiMeteo.Replace("#jour#",date.Day.ToString());
            string url_apiMeteoTrueMonth = url_apiMeteoTrueDay.Replace("#mois#",date.Month.ToString());
            string url_apiMeteoTrueAll = url_apiMeteoTrueMonth.Replace("#annee#",date.Year.ToString());
            string url_apiMeteoTrueCity = url_apiMeteoTrueAll.Replace("#ville#", ville);
            //http://weather.yahooapis.com/forecastrss?w=location
            string urlImage = XDocument.Load(url_apiMeteo).Root.Element("data").Element("weather").Element("weatherIconUrl").Value;
            return urlImage;
        }



        public static int convertisseurMoisEnInt(string dateMois)
        {
            int mois = 0; 
            switch (dateMois)
            {
                case "Jan": mois = 1;
                    break;
                case "Feb": mois = 2;
                    break;
                case "Mar": mois = 3;
                    break;
                case "Apr": mois = 4;
                    break;
                case "May": mois = 5;
                    break;
                case "Jun": mois = 6;
                    break;
                case "Jul": mois = 7;
                    break;
                case "Aug": mois = 8;
                    break;
                case "Sep": mois = 9;
                    break;
                case "Oct": mois = 10;
                    break;
                case "Nov": mois = 11;
                    break;
                case "Dec": mois = 12;
                    break;
            } 
            return mois;
        }



    }
}